package com.example.lanouhn.firstapp.activity.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.lanouhn.firstapp.R;
import com.example.lanouhn.firstapp.activity.model.FlagshipStore;
import com.example.lanouhn.firstapp.activity.model.GoodsList;
import com.squareup.picasso.Picasso;

import java.util.List;

/**商城旗舰店数据适配器
 * Created by lanouhn on 16/7/25.
 */
public class FlagshipStoreAdapter extends BaseAdapter {
    private Context context;
    private List<FlagshipStore> list;

    public FlagshipStoreAdapter(Context context, List<FlagshipStore> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int i) {
        return list.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder holder = null;
        if(view == null){
            //判断缓存中是否有内容  没有则创建 有的话 使用缓存中的内容
            holder = new ViewHolder();
            //绑定布局文件
            view = LayoutInflater.from(context).inflate(R.layout.flagship_store_item, null);
            //绑定控件id
            holder.flagship_store_image = (ImageView) view.findViewById(R.id.flagship_store_image);
            holder.goods_name = (TextView) view.findViewById(R.id.goods_name);
            holder.goods_price = (TextView) view.findViewById(R.id.goods_price);
            holder.evaluation_count = (TextView) view.findViewById(R.id.evaluation_count);
            //数据缓存
            view.setTag(holder);
        }else {

            holder = (ViewHolder) view.getTag();
        }
        FlagshipStore fs = list.get(i);
        //使用Picasso 加载图片
        Picasso.with(context).load(fs.getGoods_image_url()).into(holder.flagship_store_image);
        holder.goods_name.setText(fs.getGoods_name());
        holder.goods_price.setText(fs.getGoods_price());
        holder.evaluation_count.setText(fs.getEvaluation_count());
        return view;
    }


    class ViewHolder{
        private ImageView flagship_store_image;
        private TextView goods_name;
        private TextView goods_price;
        private TextView evaluation_count;



    }
}
